<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Change_password extends CI_Controller {
    public function index()
    {
        $data['title'] = "Change Password";        
        $data['data'] = array ('response'=>$this->session->flashdata('message'));
        $data['js'] = array('change_password.js');
        $data['view'] = "settings/view_change_password";
        $this->load->view('view_template',$data);
    }
    
    public function save(){
        $oldpass = encrypt_password($this->input->post('oldpass'));
        $newpass = encrypt_password($this->input->post('newpass'));
        $this->load->model('staffusers');
        
        if ($this->staffusers->updatePassword($this->session->userdata('user_id'), $oldpass, $newpass)){
            $this->session->set_flashdata('message', 'Password successfully updated');
            echo "good";
        }
        else{
            $this->session->set_flashdata('message', 'Failed: Incorrect input.');
            echo "fail";
        }
    }
 
}

